﻿function myInfo(){
			$.ajax({
				type:"post",
				/* dataType:"json", */
				url:Server+"/consum/selectInfo",
				async:false,
				data:{
					uId:$("#useridoflogin").val()
				},
				error:function(){
					alert("2")
				}, 
				success:function(res){
					var html =
//					'<div class="right">'+
					' <div class="title"><span id="span1">个人资料</span></div>'
					+'<div class="tab_header" id="topThings">'
					+'</div>'  
					+'<div class="infoList">'
					+'<ul id="orderList">'
					+'<style>.tab_header{display:none}'
					+' .mainList .content .right .infoList li {'
					+' height: 100%; '
					+' margin-bottom: 0px; '
					+' border: 0px solid #e6e6e6; '
					+'}			</style>'
					+' <div class="info-person">'
					+' 	<ul>'
					+' 		<!--头像-->'
					+' 		<li class="xixihahawowo">'
					+' 			<div id="preview">'
					+' 				<img id="imghead" width=100% height=auto border=0 />'
					+' 			</div>'
					+' 			<label class="wahaha">上传头像</label>'
					+' 			<input  class="xixixdsfsafasfafasd" id="image" type="file" onchange="previewImage(this)" style="border: none;'
					+'  outline: none;" '
					+' padding-top: 20px;"/>'
					+' 		</li>'
					+' 		<li class="xixihahawowo">'
					+' 			<label class="wahaha">用户名&nbsp;</label>'
					+' 			<input id="userName" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 	</li>'
					+' 		<li class="item4 xixihahawowo">'
					+' 			<label class="wahaha">单位名称<span>*</span></label>'
					+'	<input id="unitName" type="text" name="" value=""/>'
					+' 		</li>'
					+' 	<li class="xixihahawowo">'
					+' 		<label class="wahaha">单位地址</label>'
					+' 		<input id="unitAddress" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 	</li>'
					+' 	<li class="xixihahawowo">'
					+' 		<label class="wahaha">联系电话</label>'
					+' 		<input id="mobile" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 	</li>'
					+' 	<li class="xixihahawowo">'
					+' 			<label class="wahaha">电子邮箱</label>'
					+' 		<input id="emaile" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 	</li>'
					+' 	<li class="xixihahawowo">'
					+' 		<label class="wahaha">身份证件</label>'
					+' 		<input id="idCard" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 	</li>'
					+' 	<li class="xixihahawowo">'
					+' 			<label class="wahaha">真实姓名</label>'
					+' 			<input id="realName" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 	</li>'
					+' 	<li class="xixihahawowo">'
					+' 		<label class="wahaha">邮政编码</label>'
					+' 		<input id="zip" class="xixixdsfsafasfafasd" type="text" name=""  value="" />'
					+' 		</li>'

					+' </ul>'
					+' </div>'
					+' <!--btn-->'
					+' <div class="btn-info-person12432425235">'
					+' 	<a onclick="tijiao()"  class="btn-onegvusfbdivsbvisdbvs">保存</a>'
					+' </div>'
					+' </div>'
//					+' </div>'
					+'<link rel="stylesheet" href="new_css/user3.css">'
					+'</div>'
					+'</ul>'
					$("#right333").html(html);
					$("#userName").val(res.userName);
					$("#unitName").val(res.unitName);
					$("#unitAddress").val(res.unitAddress);
					$("#realName").val(res.realName);
					$("#mobile").val(res.mobile);
					$("#emaile").val(res.emaile);
					$("#idCard").val(res.idCard);
					$("#zip").val(res.zip);
					/* imageUpload=res.imageUpload */
				},
				error:function(res){
					alert("false");
				}
			}),
			$.ajax({
				type:"post",
				url:Server+"/consum/getImage",
				data:{
					uId:$("#useridoflogin").val()
				},
				success:function(res){
					console.log(res)
					$("#imghead").prop("src",res);
				}
			})
}
function tijiao(){
	/*alert($("#userName").val());
}
//$(function(){
$("#sumbit").click(function(){
	alert("11");*/
	var url;
	var formData=new FormData();	//使用formData实现图片上传
	var img_file=document.getElementById("image");
	var fileObj=img_file.files[0];
	formData.append("file",fileObj);
	$.ajax({
		type:"post",
		/* dataType:"json", */
//		url :"http://localhost/info/uploadImage",
		url:Server+"/info/uploadImage",
		data:formData,
		processData : false,
		contentType : false,
		async:false,
		error:function(){
			alert("2")
		}, 
		success:function(res){
			console.log(res)
			if(res.code==500){
				url=' '
			}else{
				url=res
			}
			
		}
	}),
	$.ajax({
		type:"post",
		/* dataType:"json", */
//		url :"http://localhost/consum/updateInfo",
		url:Server+"/consum/updateInfo",
		data:{
			userName:$("#userName").val(),
			unitName:$("#unitName").val(),
			unitAddress:$("#unitAddress").val(),
			realName:$("#realName").val(),
			mobile:$("#mobile").val(),
			emaile:$("#emaile").val(),
			idCard:$("#idCard").val(),
			zip:$("#zip").val(),
			imageUpload:url,
			uId:$("#useridoflogin").val(),
//			ouId:
		},
		/* error:function(){
			alert("2")
		}, */
		success:function(res){
			if(res==1){
				alert("修改成功")
			}
		},
		error:function(res){
			alert("修改失败");
		}
	})
}

//})
function previewImage(file)
    {
        var MAXWIDTH  = 260;
        var MAXHEIGHT = 180;
        var div = document.getElementById('preview');
        if (file.files && file.files[0])
        {
            div.innerHTML ='<img id=imghead>';
            var img = document.getElementById('imghead');
            img.onload = function(){
                var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
                img.width  =  rect.width;
                img.height =  rect.height;
//                 img.style.marginLeft = rect.left+'px';
                img.style.marginTop = rect.top+'px';
            }
            var reader = new FileReader();
            reader.onload = function(evt){img.src = evt.target.result;}
            reader.readAsDataURL(file.files[0]);
        }
        else //兼容IE
        {
            var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
            file.select();
            var src = document.selection.createRange().text;
            div.innerHTML = '<img id=imghead>';
            var img = document.getElementById('imghead');
            img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
            var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
            status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
            div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;"+sFilter+src+"\"'></div>";
        }
    }
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
        var param = {top:0, left:0, width:width, height:height};
        if( width>maxWidth || height>maxHeight )
        {
            rateWidth = width / maxWidth;
            rateHeight = height / maxHeight;

            if( rateWidth > rateHeight )
            {
                param.width =  maxWidth;
                param.height = Math.round(height / rateWidth);
            }else
            {
                param.width = Math.round(width / rateHeight);
                param.height = maxHeight;
            }
        }
        param.left = Math.round((maxWidth - param.width) / 2);
        param.top = Math.round((maxHeight - param.height) / 2);
        return param;
    }